home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QRZ! Ham Radio 8
/
QRZ Ham Radio Callsign Database - Volume 8.iso
/
pc
/
files
/
t_unix
/
bs941029.tgz
/
bbsx-941029.tar
/
bbsx
/
convind.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-29
|
2KB
|
97 lines
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <sys/types.h>
#include <pwd.h>
#include <fcntl.h>
#include "bbs.h"
#include "bbs.hd"
struct old_index {
long size;
long date;
int mesg;
char bid[LEN_BID+1];
char lifetime_h;
char subject[LEN_SUBJECT+1];
char lifetime_l;
char to[LEN_TO+1];
char at[LEN_AT+1];
char from[LEN_FROM+1];
char deleted;
};
const struct cmdtable cmdtable[1];
main() {
struct passwd *pw;
struct index index;
struct old_index old_index;
int i;
int old_ind, new_ind;
char line[1204];
if (getuid()) {
perror("permission denied");
return 1;
}
if (chdir(WRKDIR)) {
mkdir(WRKDIR, 0755);
if (chdir(WRKDIR)) halt();
}
read_config();
sprintf(line,"%s.o",INDEXFILE);
if(link(INDEXFILE, line) == -1) {
perror("can't rename old indexfile");
return;
}
if(unlink(INDEXFILE) == -1) {
perror("can't remove old indexfile");
return;
}
if ((new_ind = open(INDEXFILE, O_RDWR | O_CREAT, 0644)) < 0) {
perror("can't open new indexfile");
return;
}
if ((old_ind = open(line, O_RDONLY, 0644)) < 0) {
perror("can't open old indexfile");
return;
}
for (;;) {
if (read(old_ind,&old_index, sizeof(struct old_index)) < 1) break;
if (!old_index.deleted) {
index.size = old_index.size;
index.date = old_index.date;
index.mesg = old_index.mesg;
strcpy(index.bid, old_index.bid);
index.lifetime_h = old_index.lifetime_h;
index.lifetime_l = old_index.lifetime_l;
strcpy(index.subject, old_index.subject);
strcpy(index.to, old_index.to);
strcpy(index.orig_to, old_index.to);
strcpy(index.at, old_index.at);
strcpy(index.from, old_index.from);
index.flags = 0;
if(write(new_ind, &index, sizeof(struct index)) != sizeof(struct index))
halt();
}
}
close(old_ind);
close(new_ind);
unlink(line);
return;
}